/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: ActivitySchedule
 * Author:   zhouheng
 * Date:     2019/8/4 13:26
 * Description: 活动定时任务
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhouh.golden.activity.task;

import com.zhouh.golden.activity.dao.ActDrawAwardItemMapper;
import com.zhouh.golden.activity.domain.ActDrawAwardItem;
import com.zhouh.golden.activity.service.processor.constants.DrawContants;
import com.zhouh.golden.activity.util.RedisManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈活动定时任务〉
 *
 * @author zhouheng
 * @create 2019/8/4
 * @since 1.0.0
 */
@Component
@EnableScheduling
public class ActivitySchedule {

    @Autowired
    ActDrawAwardItemMapper actDrawAwardItemMapper;

    @Autowired
    RedisTemplate<String,Object> redisTemplate;

    /**
     * @description: 定时任务初始化活动每天的库存量
     * @date: 2019/8/4 13:29
     * @author:zhouheng
     */

//    @Scheduled(cron = "0 0 0 * * ? ")
    @Scheduled(cron = "0 54 15 24 8 ? ")
    public void initDrawItemStock() {
        // 从redis中获取需要初始化的库存
        List<ActDrawAwardItem> actDrawAwardItems = (List<ActDrawAwardItem>) redisTemplate.opsForValue().get(DrawContants.DRAW_ITEM);
        if (CollectionUtils.isEmpty(actDrawAwardItems)){
            return;
        }

        actDrawAwardItemMapper.batchUpdate(actDrawAwardItems);
    }

    @Scheduled(cron="0 0/1 * * * ?")
    public void testSchedule(){
        System.out.println(System.currentTimeMillis());
    }
}